/*
 * USART_SPI.c
 *
 * Created: 2012-06-02 15:17:29
 *  Author: Sebastian_2
 */ 

#include "USART_SPI.h"

#ifndef ATMEGA

void USART_SPI_Init(USART_t *USART, uint32_t baud) {
	USART->BAUDCTRLA = baud;
	USART->BAUDCTRLB = baud << 8;
	USART->CTRLB = USART_TXEN_bm | USART_RXEN_bm;
	USART->CTRLC = USART_CMODE_MSPI_gc;
}

void USART_SPI_Write(USART_t *USART, uint8_t d) {
	USART->DATA = d;
	while(!(USART->STATUS & USART_TXCIF_bm));
	USART->STATUS = USART_TXCIF_bm;
}

uint8_t USART_SPI_Read(USART_t *USART) {
	while(!(USART->STATUS & USART_RXCIF_bm));
	return USART->DATA;
}

#endif